#include "custombutton.h"
#include <QDebug>
#include <QTimer>
#include <QPropertyAnimation>

/*
CustomButton::CustomButton(QWidget *parent) : QPushButton(parent)
{
}
*/
CustomButton::CustomButton(QString normal, QString press)
{
    this->m_normal_img_path = normal;
    this->m_press_img_path = press;
    QPixmap pix;
    bool ret = pix.load(normal);
    if(!ret)
    {
        qDebug() << "图片加载失败";
        return;
    }
    // 设置图片固定大小
    this->setFixedSize(pix.width(),pix.height());
	this->setStyleSheet("QPushButton{border:0px;}");
    this->setIcon(pix);
    this->setIconSize(QSize(pix.width(),pix.height()));
}
void CustomButton::mousePressEvent(QMouseEvent *e)
{
    if(m_press_img_path != NULL)
    {
        QPixmap pix;
        bool ret = pix.load(this->m_press_img_path);
        if(!ret)
        {
            qDebug() << "图片加载失败";
            return;
        }
        // 设置图片固定大小
        this->setFixedSize(pix.width(),pix.height());
        this->setIcon(pix);
        this->setIconSize(QSize(pix.width(),pix.height()));
    }

    return QPushButton::mousePressEvent(e);
}
void CustomButton::mouseReleaseEvent(QMouseEvent *e)
{
    if(m_press_img_path != NULL)
    {
        QPixmap pix;
        bool ret = pix.load(this->m_normal_img_path);
        if(!ret)
        {
            qDebug() << "图片加载失败";
            return;
        }
        // 设置图片固定大小
        this->setFixedSize(pix.width(),pix.height());
        this->setIcon(pix);
        this->setIconSize(QSize(pix.width(),pix.height()));
    }

    return QPushButton::mouseReleaseEvent(e);
}
void CustomButton::zoom1()
{
    QPropertyAnimation * animation = new QPropertyAnimation(this,"geometry");
	animation->setDuration(500);
    animation->setStartValue(QRect(this->x(),this->y(),this->width(),this->height()));
    animation->setEndValue(QRect(this->x(),this->y()+50,this->width(),this->height()));
    animation->setEasingCurve(QEasingCurve::OutBounce);
    animation->start();
}
void CustomButton::zoom2()
{
    QPropertyAnimation * animation = new QPropertyAnimation(this,"geometry");
	animation->setDuration(500);
    animation->setStartValue(QRect(this->x(),this->y(),this->width(),this->height()));
    animation->setEndValue(QRect(this->x(),this->y()-50,this->width(),this->height()));
    animation->setEasingCurve(QEasingCurve::OutBounce);
    animation->start();
}
